<?php

##################################################
#
# Copyright (c) 2004-2006 OIC Group, Inc.
# Written and Designed by James Hunt
#
# This file is part of Exponent
#
# Exponent is free software; you can redistribute
# it and/or modify it under the terms of the GNU
# General Public License as published by the Free
# Software Foundation; either version 2 of the
# License, or (at your option) any later version.
#
# GPL: http://www.gnu.org/licenses/gpl.txt
#
##################################################

class dailydevotionmodule_config {
	function form($object) {
		global $db;
		
		$i18n = exponent_lang_loadFile('datatypes/dailydevotion_config.php');

		if (!defined('SYS_FORMS')) require_once(BASE.'subsystems/forms.php');
		exponent_forms_initialize();
		
		$form = new form();
		if (!isset($object->id)) {
			$object->host_location_data = '';
			$object->items=5;
		} else {
			$form->meta('id',$object->id);
		}
		
		// search any where to get all the article module
		$host=array();
		$sql="SELECT {$db->prefix}container.title title, {$db->prefix}container.internal location,  {$db->prefix}article.id FROM {$db->prefix}article INNER JOIN {$db->prefix}container
			  ON {$db->prefix}article.location_data = {$db->prefix}container.internal GROUP BY {$db->prefix}article.location_data";
		$data=$db->selectObjectsBySql($sql);
		
		foreach  ($data as $k=>$v)
		{
			$host[$v->id]=$v->title;
			if ($v->location==$object->host_location_data)
				$object->host_location_data=$v->id;
		}
		
		$form->register('items',$i18n['items'],new textcontrol($object->items));
		$form->register('host_location_data',$i18n['host'],new dropdowncontrol($object->host_location_data,$host));
		
		$form->register('submit','',new buttongroupcontrol($i18n['save'],'',$i18n['cancel']));
		
		return $form;
	}
	
	function update($values,$object) {
		global $db;
		$id=$values['host_location_data'];
		$data=$db->selectObject("article","id = {$id}");
		$object->host_location_data = $data->location_data;
		$object->items = $values['items'];
		return $object;
	}
}

?>
